from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from contacts_example import *

class MainPage(webapp.RequestHandler):
  def get(self):
	self.response.out.write(
		'Hello, modified webapp World!'
		'<html><body><form action="/contacts" method="post">'
		'username<br /><input type="text" name="username" size="20" /><br />'
		'password<br /><input type="password" name="password" size="20" /><br />'
		'name<br /><input type="text" name="name" size="20" /><br />'
		'phone<br /><input type="text" name="phone" size="20" /><br />'
		'email<br /><input type="text" name="email" size="20" /><br />'
		'<br /><input type="submit" value="Contacts" /></form></body></html>')

class ContactsPage(webapp.RequestHandler):
	def post(self):
		self.response.headers['Content-Type'] = 'text/plain'
		un = self.request.get('username')
		pw = self.request.get('password')
		nn = self.request.get('name')
		ph = self.request.get('phone')
		em = self.request.get('email')
		sample = ContactsSample(un, pw)
		ret = sample.CreateContact(nn, ph, em)
		#sample.ListAllContacts()
		#self.response.out.write('username = %s \npassword = %s\nname = %s\nphone = %s\nemail = %s' % (un, pw, nn, ph, em) )
		self.response.out.write( ret )
		
application = webapp.WSGIApplication(
                                     [('/', MainPage),
									 ('/contacts', ContactsPage)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()